package han.study.spring;

import com.alibaba.druid.pool.DruidDataSource;
import han.study.spring.bean.Dept;
import han.study.spring.bean.Emp;
import han.study.spring.collectionType.Course;
import han.study.spring.collectionType.Student;
import han.study.spring.service.UserService;
import han.study.spring.service.UserService2;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UnitTest {
    @Test
    public void OrderTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("user-bean.xml");
        Orders orders = context.getBean("orders",Orders.class);
        System.out.println(orders);
        System.out.println(orders.getName());
    }

    @Test
    public void bookTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("user-bean.xml");
        Book book = context.getBean("book",Book.class);
        System.out.println(book);
        System.out.println(book.getName());
    }

    @Test
    public void userTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("user-bean.xml");
        User user = context.getBean("user",User.class);
        System.out.println(user);
        user.add();
    }

    @Test
    public void nullTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("user-bean.xml");
        Orders order = context.getBean("order",Orders.class);
        System.out.println(order);
        System.out.println(order.getAddress());
    }

    @Test
    public void serviceTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean2.xml");
        UserService service = context.getBean("user-service",UserService.class);
        service.add();
    }

    @Test
    public void empTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean3.xml");
        Emp emp = context.getBean("emp", Emp.class);
        Dept dept = emp.getDept();
        System.out.println(dept);
    }
    @Test
    public void empTest2(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean4.xml");
        Emp emp = context.getBean("emp",Emp.class);
        Dept dept = emp.getDept();
        System.out.println(dept);
    }

    @Test
    public void studentTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("collbean.xml");
        Student stu = context.getBean("student", Student.class);
        System.out.println(stu);
    }

    @Test
    public void myBeanTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("collbean2.xml");
        Course course = context.getBean("myBean", Course.class);
        System.out.println(course);
    }

    @Test
    public void autoWriteTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("collbean.xml");
        Course course = context.getBean("course",Course.class);
        System.out.println(course);
    }

    @Test
    public void dataSourceTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("collbean2.xml");
        DruidDataSource dataSource = context.getBean("dataSource",DruidDataSource.class);
        System.out.println(dataSource);
        dataSource.close();
    }

    @Test
    public void testService(){
        ApplicationContext context = new ClassPathXmlApplicationContext("collbean2.xml");
        UserService2 service = context.getBean("userService2", UserService2.class);
        service.update();
    }
}
